<?php
header("Content-Type: text/html; charset=iso-8859-1");
require('include.php');
if(check_admin()){
	$membre_id = (!empty($_REQUEST['membre'])) ? $_REQUEST['membre'] : "";
	$commission_id = (!empty($_REQUEST['commission'])) ? $_REQUEST['commission'] : "";
	$fonction = (!empty($_REQUEST['fonction'])) ? $_REQUEST['fonction'] : "";
	if($membre_id && $commission_id && $fonction){
		$q = "select description as nom from commissions where id = '$commission_id'";
		$r = ExecRequete($q);
		$commission = ($s = LigneSuivante($r)) ? $s->nom : "";
		if($fonction =='new'){
			echo "<p class = 'center bold'>$commission : nouvelle fonction</p>\n";
			echo "<form action = 'update_membre_admin.php' name = 'form_membre_admin' id = 'form_membre_admin'>\n";
			echo "<p class = 'center'><span class = 'bold'>Fonction: </span><input type = 'text' id = 'fonction' name = 'fonction' size = '15' />";
			echo "<input type = 'hidden' name = 'membre' value = '$membre_id' />";
			echo "<input type = 'hidden' name = 'commission' value = '$commission_id' />";
			echo "&nbsp;<button type = 'button' onclick  = 'submit_membre_admin($commission_id)' name = 'submit'>valider</button>&nbsp;<button type = 'button' onclick = 'center_box(0)'>annuler</button></p></form>\n";
		}
		else{
			$q = "select * from membre_commissions where membre_id = '$membre_id' and commission_id = '$commission_id' and fonction = '$fonction'";
			$r = ExecRequete($q);
			if($s = LigneSuivante($r)){
				$q1 = "delete from membre_commissions where membre_id = '$membre_id' and commission_id = '$commission_id' and fonction = '$fonction'";
				$return = (ExecRequete($q1)) ? "OK" : "KO";
				if($return == "OK"){
					$value = "<span class = 'fade'>aucune fonction</span>";
					$value .= "&nbsp;<a href = \"javascript:update_membre_admin($membre_id,$commission_id,'new')\"><img src = 'images/icon_new.png' alt = 'ajouter' width = '14' height = '14' /></a>";
					$value = "<span id = 'commission_$s->id'>".$value."</span>";
					$return .= "<!--!>$value";
				}
			}
			else{
				$q1 = "insert into membre_commissions (membre_id, commission_id, fonction) values ($membre_id,$commission_id,'".(addslashes($fonction))."')";
				$return = (ExecRequete($q1)) ? "OK" : "KO";
				$value =  $fonction;
				$value .= "&nbsp;<a href = \"javascript:update_membre_admin($membre_id,$commission_id,'".$fonction."')\"<img src = 'images/icon_delete.png' alt = 'supprimer' width = '14' height = '14' /></a>";
				$return .= "<!--!>".(utf8_decode($value))."";
			}
			echo $return;
		}
	}
	else echo "KO<!--!>la fonction est vide";
}
else echo "KO<!--!>permission refusée";
?>
